def run_process(cmd : String, params : Array(String), env : Hash(String, String))
	unless Process.run(cmd, params, env,
			false # clear environment
			# input:   Process::Redirect::Inherit,
			# output:  Process::Redirect::Inherit,
			# error:   Process::Redirect::Inherit
		).success?
		raise "cannot run #{cmd} #{params.join(" ")}"
	end
end

# Send a token to recovery the user's password.
def send_recovery_token(authd : AuthD::Service, login : String, email : String, token : String)
	run_process(authd.configuration.mailer_exe,
		[ "send", authd.configuration.recovery_template, email ],
		{ "HOME" => "/", "LOGIN" => login, "TOKEN" => token })
end

# Send a token to validate the user's email address.
def send_activation_token(authd : AuthD::Service, login : String, email : String, token : String)
	run_process(authd.configuration.mailer_exe,
		[ "send", authd.configuration.activation_template, email ],
		{ "HOME" => "/", "LOGIN" => login, "TOKEN" => token })
end
